/**
 * @project_name staff_vehicle
 * @package_name com.ssh.web.admin
 * @desc TODO
 * @param
 * @author jack
 * @date 2013-4-27
 * @time 下午2:45:40
 */
package com.ssh.web.admin;

import java.io.File;

import com.opensymphony.xwork2.ActionSupport;
import com.ssh.entity.Staff;
import com.ssh.ser.admin.StaffManageSerI;
import com.ssh.util.UploadFileUtil;

/**
 * @author jack
 *
 */
public class EditStaffAction extends ActionSupport {
	/**
	 * TODO
	 */

	private static final long serialVersionUID = 1L;
	/**
	 * @return the serialversionuid
	 */
	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	private String departmentName;
	public Staff editStaff;
	private String education;
	private String OpSId;
	private File pic;
	private String picContentType;

	private String picFileName;
	private String picture;
	private String staffId;
	public Staff alterStaff;

	private StaffManageSerI staffManageSerI;

	public String editStaff() {
		try {
			if(!editStaff.getStaffId().equals("")){
				alterStaff = staffManageSerI.viewById(editStaff.getStaffId());
				String path = "upload/image_staff_vehicle";
				boolean sta = UploadFileUtil.save(pic, picFileName, path);
				if (sta) {
					editStaff.setPicture(path + "/" + picFileName);
				}
				String depId = staffManageSerI.getPosByName(departmentName)
						.getPositionId();
				if (depId != null)
					if(!depId.equals(""))
					editStaff.setPositionPositionId(depId);
				/*
				 * if(!education.equals("")) editStaff.setEducation(education);
				 */
				alterStaff.setAddress(editStaff.getAddress());
				alterStaff.setFirstName(editStaff.getFirstName());
				alterStaff.setLastName(editStaff.getLastName());
				alterStaff.setSex(editStaff.getSex());
				alterStaff.setMarriage(editStaff.getMarriage());
				alterStaff.setEmail(editStaff.getEmail());
				alterStaff.setEducation(editStaff.getEducation());
				alterStaff.setStaffId(editStaff.getStaffId());
				alterStaff.setPicture(editStaff.getPicture());
				alterStaff.setPoliticsState(editStaff.getPoliticsState());
				alterStaff.setBirthday(editStaff.getBirthday());
				alterStaff.setPositionPositionId(editStaff.getPositionPositionId());
				alterStaff.setEducation(editStaff.getEducation());
				staffManageSerI.editStaff(alterStaff);
			}

		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}

		return "ok";
	}

	/*
	 * (non-Javadoc)
	 *
	 * @see com.opensymphony.xwork2.ActionSupport#execute()
	 */
	@Override
	public String execute() throws Exception {
		// TODO Auto-generated method stub
		return showEditStaffProfie();
	}

	/**
	 * @return the departmentName
	 */
	public String getDepartmentName() {
		return departmentName;
	}

	/**
	 * @return the editStaff
	 */
	public Staff getEditStaff() {
		return editStaff;
	}

	/**
	 * @return the education
	 */
	public String getEducation() {
		return education;
	}

	/**
	 * @return the opSId
	 */
	public String getOpSId() {
		return OpSId;
	}

	/**
	 * @return the pic
	 */
	public File getPic() {
		return pic;
	}

	/**
	 * @return the picContentType
	 */
	public String getPicContentType() {
		return picContentType;
	}

	/**
	 * @return the picFileName
	 */
	public String getPicFileName() {
		return picFileName;
	}

	/**
	 * @return the picture
	 */
	public String getPicture() {
		return picture;
	}

	/**
	 * @return the staffId
	 */
	public String getStaffId() {
		return staffId;
	}

	/**
	 * @return the staffManageSerI
	 */
	public StaffManageSerI getStaffManageSerI() {
		return staffManageSerI;
	}

	/**
	 * @param departmentName
	 *            the departmentName to set
	 */
	public void setDepartmentName(String departmentName) {
		this.departmentName = departmentName;
	}

	/**
	 * @param editStaff
	 *            the editStaff to set
	 */
	public void setEditStaff(Staff editStaff) {
		this.editStaff = editStaff;
	}

	/**
	 * @param education
	 *            the education to set
	 */
	public void setEducation(String education) {
		this.education = education;
	}

	/**
	 * @param opSId
	 *            the opSId to set
	 */
	public void setOpSId(String opSId) {
		OpSId = opSId;
	}

	/**
	 * @param pic
	 *            the pic to set
	 */
	public void setPic(File pic) {
		this.pic = pic;
	}

	/**
	 * @param picContentType
	 *            the picContentType to set
	 */
	public void setPicContentType(String picContentType) {
		this.picContentType = picContentType;
	}

	/**
	 * @param picFileName
	 *            the picFileName to set
	 */
	public void setPicFileName(String picFileName) {
		this.picFileName = picFileName;
	}

	/**
	 * @param picture
	 *            the picture to set
	 */
	public void setPicture(String picture) {
		this.picture = picture;
	}

	/**
	 * @param staffId
	 *            the staffId to set
	 */
	public void setStaffId(String staffId) {
		this.staffId = staffId;
	}

	/**
	 * @param staffManageSerI
	 *            the staffManageSerI to set
	 */
	public void setStaffManageSerI(StaffManageSerI staffManageSerI) {
		this.staffManageSerI = staffManageSerI;
	}

	public String showEditStaffProfie() {
		try {
			editStaff = staffManageSerI.viewById(OpSId);
		} catch (Exception e) {
			e.printStackTrace();
			return "error";
		}

		return "pageAmendStaff";
	}

	/**
	 * @return the alterStaff
	 */
	public Staff getAlterStaff() {
		return alterStaff;
	}

	/**
	 * @param alterStaff the alterStaff to set
	 */
	public void setAlterStaff(Staff alterStaff) {
		this.alterStaff = alterStaff;
	}

}